function red() {
    console.log('red')
}
function yellow() {
    console.log('yellow')
}
function green() {
    console.log('green')
}
function lights(light,time) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            if (light === 'red') {
                red()
            }
            else if (light === 'yellow') {
                yellow()
            }
            else {
                green()
            }
            //? 放到这里面让他在打印颜色后执行
            resolve()
        },time)
    })
}
const task = () => {
    lights('red',3000).then(_ => lights('yellow',1000)).then(_ => lights('green',2000)).then(task)
}
task()

async function aw() {
    await lights('red',3000)
    await lights('yellow',1000)
    await lights('green',2000)
    await aw()
}
aw()
